package zhihuilan.controlle.wechatMini;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zhihuilan.common.WxMiniResponse;
import zhihuilan.common.enums.ResultEnum;
import zhihuilan.common.utils.BaiduMapUtils;
import zhihuilan.common.utils.ToolsUtils;
import zhihuilan.controlle.BasicController;
import zhihuilan.dto.*;
import zhihuilan.entity.*;
import zhihuilan.entity.tools.ToolsLocation;
import zhihuilan.entity.tools.baidu.BaiduAddressComponent;
import zhihuilan.entity.tools.baidu.BaiduReverseGeocoding;
import zhihuilan.params.StaticParam;
import zhihuilan.params.query.*;
import zhihuilan.params.save.MyCircleSaveParam;
import zhihuilan.service.*;

import javax.annotation.Resource;
import java.util.*;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
 * 小程序端API </p>
 * 接口说明：</p>
 *
 * @Module 线缆圈圈子（首页推荐）信息接口模块
 * @Author chenk
 * @Version 1.0.1 (2025-02-24)
 */
@Slf4j
@RestController
@RequestMapping("/app/Circle")
public class MyCircleController extends BasicController {
    Logger logger = Logger.getLogger(MyCircleController.class.getName());

    @Resource
    private MyCircleService myMemberService;

    @Resource
    private MyConfigService myConfigService;

    @Resource
    MyCircleService myCircleService;

    @Resource
    private MyStaffShopGoodsService myStaffShopGoodsService;

    @Resource
    private MyCircleDiscussService myCircleDiscussService;

    @Resource
    private MyCircleThumbupService myCircleThumbupService;

    @Resource
    private MyCircleCollectionService myCircleCollectionService;

    @Resource
    private MyFactoryFavService myFactoryFavService;

    @Resource
    private MyCircleDiscussThumbupService myCircleDiscussThumbupService;

    /**
     * 新增推荐信息
     *
     * @param saveParam 推荐信息【MyCircleQueryParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @ApiNote 支持推荐信息组合查询
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setCircleInfo")
    public WxMiniResponse setCircleInfo(@RequestBody MyCircleSaveParam saveParam) {
        if (!this.isCheckLogin(saveParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
//        if (ObjectUtils.isEmpty(currentStaff.getUtype())) {
//            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请先完善店铺信息");
//        }
//        if (!currentStaff.getUtype().equals(1) || ObjectUtils.isEmpty(currentStaff.getLogo())) {
//            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "请先完善店铺信息");
//        }
        if (ObjectUtils.isEmpty(saveParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数校验失败：传入参数为空！");
        }
        MyCircle saveEntity = new MyCircle();
        BeanUtils.copyProperties(saveParam, saveEntity);
        MyCircleQueryParam queryParam = new MyCircleQueryParam();
        queryParam.setStaffId(currentStaff.getId());
        queryParam.setCreateTime(ToolsUtils.getTodayZeroTime() / 1000);
        if (!ObjectUtils.isEmpty(saveEntity.getType()))
            queryParam.setType(saveEntity.getType());
        if (!ObjectUtils.isEmpty(saveEntity.getBuy()) && saveEntity.getBuy() == 1)
            queryParam.setBuy(saveEntity.getBuy());
        Long todaySendCount = this.myMemberService.getTodaySendCount(queryParam);
        if (!ObjectUtils.isEmpty(saveEntity.getBuy()) && "1".equals(saveEntity.getBuy())) {
            MyConfig myConfig = myConfigService.selectByName("paidSendCricle");
            if (todaySendCount >= Long.parseLong(myConfig.getValue())) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "每天限制发" + myConfig.getValue() + "条动态！");
            }
        } else {
            MyConfig myConfig = myConfigService.selectByName("freeSendCircle");
            if (todaySendCount >= Long.parseLong(myConfig.getValue())) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "每天限制发" + myConfig.getValue() + "条动态！");
            }
        }
        String errorMsg = this.isValidContent(saveEntity.getContent());
        if (!ObjectUtils.isEmpty(errorMsg))
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), errorMsg);
        String traceId = "";
        if (!ObjectUtils.isEmpty(saveEntity.getImage())) {
            List<String> images = Arrays.asList(saveEntity.getImage().split(","));
            List<String> tids = new ArrayList<>();
            for (String item : images) {
                try {
                    String checkFt = ToolsUtils.verifymedia(item, currentStaff.getOpenid(), "2", this.wxMaService);
                    JSONObject jsonObject = JSONObject.parseObject(checkFt);
                    if (!ObjectUtils.isEmpty(jsonObject)) {
                        String trace_id = jsonObject.getString("trace_id");
                        if (!ObjectUtils.isEmpty(trace_id)) {
                            tids.add(trace_id);
                        }
                    }
                } catch (Exception e) {
                    WxMiniResponse.error(ResultEnum.ERROR.getKey(), e.getMessage());
                }
            }
            if (!ObjectUtils.isEmpty(tids)) {
                traceId = String.join(",", tids);
            }
        }
        if (!ObjectUtils.isEmpty(saveEntity.getVideo())) {
            List<String> tids = new ArrayList<>();
            for (int i = 0; i < 100; i += 30) {
                try {
                    String checkFt = ToolsUtils.verifymedia(saveEntity.getVideo() + "?x-oss-process=video/snapshot,t_" + i + ",f_jpg,ar_auto", currentStaff.getOpenid(), "2", this.wxMaService);
                    JSONObject jsonObject = JSONObject.parseObject(checkFt);
                    if (!ObjectUtils.isEmpty(jsonObject)) {
                        String trace_id = jsonObject.getString("trace_id");
                        if (!ObjectUtils.isEmpty(trace_id)) {
                            tids.add(trace_id);
                        }
                    }
                } catch (Exception e) {
                    WxMiniResponse.error(ResultEnum.ERROR.getKey(), e.getMessage());
                }
            }
            if (!ObjectUtils.isEmpty(tids)) {
                traceId = String.join(",", tids);
            }
        }

        if (ObjectUtils.isEmpty(saveEntity.getId())) {
            saveEntity.setCreateTime(new Date().getTime() / 1000);
            saveEntity.setCreateUser(currentStaff.getId() + "");
        } else {
            saveEntity.setUpdateTime(new Date().getTime() / 1000);
            saveEntity.setUpdateUser(currentStaff.getId() + "");
        }

        saveEntity.setStaffId(currentStaff.getId());
        saveEntity.setTraceId(traceId);
//        saveEntity.setTitle();
        // 将'＊', '*', 'x', 'X', '×', '✘'替换成小写的*
        saveEntity.setTitle(ToolsUtils.replaceCharToSearch(currentStaff.getUserreal()));
        saveEntity.setContent(ToolsUtils.replaceCharToSearch(saveEntity.getContent()));
        saveEntity.setLat(currentStaff.getLat());
        saveEntity.setLng(currentStaff.getLng());
        saveEntity.setLatgd(!ObjectUtils.isEmpty(currentStaff.getLatgd()) ? currentStaff.getLatgd() : "");
        saveEntity.setLnggd(!ObjectUtils.isEmpty(currentStaff.getLnggd()) ? currentStaff.getLnggd() : "");
        saveEntity.setRegion(!ObjectUtils.isEmpty(currentStaff.getRegion()) ? currentStaff.getRegion() : "");
        saveEntity.setDistrictid(!ObjectUtils.isEmpty(currentStaff.getDistrictid()) ? currentStaff.getDistrictid() : "");
        saveEntity.setDistrictid1(!ObjectUtils.isEmpty(currentStaff.getDistrictid1()) ? currentStaff.getDistrictid1() : "");
        saveEntity.setDistrictid2(!ObjectUtils.isEmpty(currentStaff.getDistrictid2()) ? currentStaff.getDistrictid2() : "");
        saveEntity.setAddress(currentStaff.getAddress());
        saveEntity.setUserId(currentStaff.getId());
        saveEntity.setUserName(!ObjectUtils.isEmpty(currentStaff.getUserreal()) ? currentStaff.getUserreal() : currentStaff.getTitle());
        saveEntity.setLogo(currentStaff.getHeadimgurl());

        saveEntity.setStatus(1);
        saveEntity.setUtype(!ObjectUtils.isEmpty(currentStaff.getCategoryUtype()) ? currentStaff.getCategoryUtype() : 10);
//        saveEntity.setType(0);
        saveEntity.setIp(ToolsUtils.getIP());
        if (!ObjectUtils.isEmpty(currentStaff.getInvitecode())) {
            if (!ObjectUtils.isEmpty(currentStaff.getOutinvitetime())) {
                if (currentStaff.getOutinvitetime() > (new Date().getTime() / 1000)) {
                    saveEntity.setInvitecode(Integer.parseInt(currentStaff.getInvitecode()));
                }
            }
        } else {
            saveEntity.setInvitecode(1);
        }

        MyCircle myCircle = null;
        if (ObjectUtils.isEmpty(saveEntity.getId())) {
            myCircle = myCircleService.addEntityAndSearch(saveEntity);
        } else {
            myCircle = myCircleService.updateEntityAndSearch(saveEntity);
        }
        if (!ObjectUtils.isEmpty(myCircle)) {
            return WxMiniResponse.ok(myCircle);
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "保存失败！");
        }
    }

    /**
     * 获取动态数量
     *
     * @param queryParam 推荐信息【MyCircleQueryParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getCircleCount")
    public WxMiniResponse getCircleCount(@RequestBody MyCircleQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
//        if (ObjectUtils.isEmpty(queryParam.getStaffId())) {
//            queryParam.setStaffId(currentStaff.getId());
//        }
        queryParam.setUtype(1);
        Long count = myCircleService.selectCount(queryParam);
        if (ObjectUtils.isEmpty(count) || count == 0) {
            MyStaffShopGoodsQueryParam myStaffShopGoodsQueryParam = new MyStaffShopGoodsQueryParam();
            myStaffShopGoodsQueryParam.setStaffId(queryParam.getStaffId());
            myStaffShopGoodsQueryParam.setShopId(0);
            count = myStaffShopGoodsService.selectCount(myStaffShopGoodsQueryParam);
        }
        return WxMiniResponse.ok(count);
    }

    /**
     * 发表视频
     *
     * @param saveParam 推荐信息【MyCircleSaveParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setDetailCircleInfo")
    public WxMiniResponse setDetailCircleInfo(@RequestBody MyCircleSaveParam saveParam) {
        if (!this.isCheckLogin(saveParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(saveParam)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数校验失败：传入参数为空！");
        }
        if (ObjectUtils.isEmpty(saveParam.getVideo())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "参数校验失败：参数视频url为空！");
        }

        MyCircle saveEntity = new MyCircle();
        BeanUtils.copyProperties(saveParam, saveEntity);
        MyCircleQueryParam queryParam = new MyCircleQueryParam();
        queryParam.setStaffId(currentStaff.getId());
        queryParam.setCreateTime(ToolsUtils.getTodayZeroTime() / 1000);
        if (!ObjectUtils.isEmpty(saveEntity.getType()))
            queryParam.setType(saveEntity.getType());
        if (!ObjectUtils.isEmpty(saveEntity.getBuy()) && saveEntity.getBuy() == 1)
            queryParam.setBuy(saveEntity.getBuy());
        Long todaySendCount = this.myMemberService.getTodaySendCount(queryParam);
        if (!ObjectUtils.isEmpty(saveEntity.getBuy()) && "1".equals(saveEntity.getBuy())) {
            MyConfig myConfig = myConfigService.selectByName("paidSendCricle");
            if (todaySendCount >= Long.parseLong(myConfig.getValue())) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "每天限制发" + myConfig.getValue() + "条动态！");
            }
        } else {
            MyConfig myConfig = myConfigService.selectByName("freeSendCircle");
            if (todaySendCount >= Long.parseLong(myConfig.getValue())) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "每天限制发" + myConfig.getValue() + "条动态！");
            }
        }
        String errorMsg = this.isValidContent(saveEntity.getContent());
        if (!ObjectUtils.isEmpty(errorMsg))
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), errorMsg);

        saveEntity.setStaffId(currentStaff.getId());
        if (!ObjectUtils.isEmpty(saveEntity.getLat()) && !ObjectUtils.isEmpty(saveEntity.getLng())) {
            ToolsLocation toolsLocation = ToolsUtils.qq2baidu(saveEntity.getLat(), saveEntity.getLng());
            saveEntity.setLatgd(toolsLocation.getLat());
            saveEntity.setLnggd(toolsLocation.getLng());
            BaiduReverseGeocoding baiduReverseGeocoding = BaiduMapUtils.getBaiduAddressInfo(saveEntity.getLng(), saveEntity.getLat());
            if (!ObjectUtils.isEmpty(baiduReverseGeocoding)) {
                BaiduAddressComponent addressComponent = baiduReverseGeocoding.getResult().getAddressComponent();
                if (!ObjectUtils.isEmpty(addressComponent)) {
                    String region = addressComponent.getProvince() + "," + addressComponent.getCity() + "," + addressComponent.getDistrict();
                    saveEntity.setRegion(region);
                    String code = addressComponent.getAdcode();
                    if (!ObjectUtils.isEmpty(code)) {
                        saveEntity.setDistrictid(code);
                        saveEntity.setDistrictid1(code.substring(0, 4));
                        saveEntity.setDistrictid2(code.substring(0, 2));
                    }
                }
            }
        }
        saveEntity.setTitle(currentStaff.getUserreal());
        saveEntity.setUserId(0);
        saveEntity.setUserName(!ObjectUtils.isEmpty(currentStaff.getUserreal()) ? currentStaff.getUserreal() : currentStaff.getTitle());
        saveEntity.setLogo(currentStaff.getHeadimgurl());
        saveEntity.setStatus(1);
        saveEntity.setCreateTime(new Date().getTime() / 1000);
        saveEntity.setCreateUser(currentStaff.getId() + "");
        saveEntity.setIp(ToolsUtils.getIP());
        if (!ObjectUtils.isEmpty(currentStaff.getInvitecode())) {
            if (!ObjectUtils.isEmpty(currentStaff.getOutinvitetime())) {
                if (currentStaff.getOutinvitetime() > (new Date().getTime() / 1000)) {
                    saveEntity.setInvitecode(Integer.parseInt(currentStaff.getInvitecode()));
                }
            }
        } else {
            saveEntity.setInvitecode(1);
        }
        MyCircle myCircle = myCircleService.addEntity(saveEntity);
        if (!ObjectUtils.isEmpty(myCircle)) {
            return WxMiniResponse.ok("添加成功！");
        } else {
            return WxMiniResponse.error(3122, "保存失败！");
        }
    }

    /**
     * 获取线缆圈详细资料
     *
     * @param queryParam 推荐信息【MyCircleSaveParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getCircleInfo")
    public WxMiniResponse getCircleInfo(@RequestBody MyCircleQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam)) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "传入参数错误！");
        }
        if (ObjectUtils.isEmpty(queryParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "传入参数ID错误！");
        }
        MyCircle myCircle = null;
        if (!ObjectUtils.isEmpty(queryParam.getId())) {
            myCircle = this.myCircleService.selectById(queryParam.getId());
        } else {
            if (!ObjectUtils.isEmpty(currentStaff)) {
                myCircle = this.myCircleService.selectOne(currentStaff.getId());
            }
        }
        if (ObjectUtils.isEmpty(myCircle)) {
            return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "查询失败！没有对应条件的数据。");
        }

        MyCircleDto myCircleDto = new MyCircleDto();
        BeanUtils.copyProperties(myCircle, myCircleDto);
        MyStaff staffInfo = this.myStaffService.selectMyStaffById(myCircle.getStaffId());
        myCircleDto.setStaffLogo(staffInfo.getHeadimgurl());
        myCircleDto.setStaffHeadimgurl(staffInfo.getLogo());
        myCircleDto.setStaffTitle(staffInfo.getTitle());
        myCircleDto.setStaffLat(staffInfo.getLat());
        myCircleDto.setStaffLng(staffInfo.getLng());
        myCircleDto.setStaffAddress(staffInfo.getAddress());
        myCircleDto.setStaffAddress1(staffInfo.getAddress1());
        myCircleDto.setStaffAddress2(staffInfo.getAddress2());
        myCircleDto.setStaffRegion(staffInfo.getRegion());

        MyCircleDiscussQueryParam myCircleDiscussQueryParam = new MyCircleDiscussQueryParam();
        myCircleDiscussQueryParam.setPid(myCircle.getId());
        myCircleDiscussQueryParam.setParentid(0);
        Long discussCount = this.myCircleDiscussService.selectCount(myCircleDiscussQueryParam);
        if (ObjectUtils.isEmpty(discussCount)) {
            discussCount = 0L;
        }
        // 评论数
        myCircleDto.setDiscuss(discussCount);

        MyCircleThumbupQueryParam myCircleThumbupQueryParam = new MyCircleThumbupQueryParam();
        myCircleThumbupQueryParam.setPid(myCircle.getId());
        // 点赞数
        Long thumbups = this.myCircleThumbupService.selectCount(myCircleThumbupQueryParam);
        myCircleDto.setThumbups(thumbups);
        myCircleDto.setThumbup(1);
        if (!ObjectUtils.isEmpty(currentStaff) && !ObjectUtils.isEmpty(currentStaff.getId())) {
            myCircleThumbupQueryParam.setStaffId(currentStaff.getId());
            Long thumbup = this.myCircleThumbupService.selectCount(myCircleThumbupQueryParam);
            // 自己是否已点赞
            if (ObjectUtils.isEmpty(thumbup) || thumbup == 0L) {
                myCircleDto.setThumbup(1);
            }
        }
        // 自己是否已收藏
        MyCircleCollectionQueryParam myCircleCollectionQueryParam = new MyCircleCollectionQueryParam();
        myCircleCollectionQueryParam.setPid(myCircle.getId());
        Long collections = this.myCircleCollectionService.selectCount(myCircleCollectionQueryParam);
        myCircleDto.setCollections(collections);
        myCircleDto.setCollection(1);
        if (!ObjectUtils.isEmpty(currentStaff) && !ObjectUtils.isEmpty(currentStaff.getId())) {
            myCircleCollectionQueryParam.setStaffId(currentStaff.getId());
            Long collectionCount = this.myCircleCollectionService.selectCount(myCircleCollectionQueryParam);
            if (ObjectUtils.isEmpty(collectionCount) || collectionCount == 0L) {
                myCircleDto.setCollection(1);
            }
        }
        if (!ObjectUtils.isEmpty(currentStaff) && !ObjectUtils.isEmpty(currentStaff.getId())) {
            // 自己是否已关注
            MyFactoryFavQueryParam myFactoryFavQueryParam = new MyFactoryFavQueryParam();
            myFactoryFavQueryParam.setFavStaffid(myCircle.getStaffId());
            myFactoryFavQueryParam.setStaffId(currentStaff.getId());
            Long favCount = this.myFactoryFavService.selectCount(myFactoryFavQueryParam);
            if (ObjectUtils.isEmpty(favCount) || favCount == 0L) {
                myCircleDto.setIsfav(0);
            } else {
                myCircleDto.setIsfav(1);
            }
        } else {
            myCircleDto.setIsfav(0);
        }
        myCircleDto.setVideo(StringEscapeUtils.unescapeHtml4(myCircleDto.getVideo()));
        myCircleDto.setContent(StringEscapeUtils.unescapeHtml4(myCircleDto.getContent()));
        myCircleDto.setCompanyContent(StringEscapeUtils.unescapeHtml4(myCircleDto.getCompanyContent()));
        return WxMiniResponse.ok(myCircleDto);
    }

    /**
     * 点赞线圈
     *
     * @param queryParam 推荐信息【MyCircleQueryParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setCircleThumbup")
    public WxMiniResponse setCircleThumbup(@RequestBody MyCircleQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam) || ObjectUtils.isEmpty(queryParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }

        MyCircle myCircle = this.myCircleService.selectById(queryParam.getId());
        if (ObjectUtils.isEmpty(myCircle)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }
        MyCircleThumbupQueryParam myCircleThumbupQueryParam = new MyCircleThumbupQueryParam();
        myCircleThumbupQueryParam.setPid(myCircle.getId());
        myCircleThumbupQueryParam.setStaffId(currentStaff.getId());
        Long thumbup = this.myCircleThumbupService.selectCount(myCircleThumbupQueryParam);
        if (!ObjectUtils.isEmpty(thumbup) && thumbup > 0L) {
            Boolean result = this.myCircleThumbupService.deleteByPidAndStaffId(myCircle.getId(), currentStaff.getId());
            if (result) {
                return WxMiniResponse.ok();
            }
        } else {
            MyCircleThumbup myCircleThumbup = new MyCircleThumbup();
            myCircleThumbup.setPid(myCircle.getId());
            myCircleThumbup.setStaffId(currentStaff.getId());
            myCircleThumbup.setStaffName(currentStaff.getUserreal());
            myCircleThumbup.setCreateTime(new Date().getTime() / 1000);
            myCircleThumbup.setCreateUser(currentStaff.getId() + "");
            myCircleThumbup = this.myCircleThumbupService.addEntity(myCircleThumbup);
            if (!ObjectUtils.isEmpty(myCircleThumbup) && !ObjectUtils.isEmpty(myCircleThumbup.getId()) && myCircleThumbup.getId() > 0) {
                return WxMiniResponse.ok(myCircleThumbup);
            }
        }
        return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "点赞失败！或id不正确");
    }

    /**
     * 点赞线圈
     *
     * @param queryParam 推荐信息【MyCircleQueryParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setCircleDiscuss")
    public WxMiniResponse setCircleDiscuss(@RequestBody MyCircleDiscussQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam) || ObjectUtils.isEmpty(queryParam.getPid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }

        String errorMsg = this.isValidContent(queryParam.getContent());
        if (!ObjectUtils.isEmpty(errorMsg))
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), errorMsg);

        MyCircle myCircle = this.myCircleService.selectById(queryParam.getPid());
        if (ObjectUtils.isEmpty(myCircle)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }

        MyCircleDiscuss myCircleDiscuss = new MyCircleDiscuss();
        BeanUtils.copyProperties(queryParam, myCircleDiscuss);
        myCircleDiscuss.setPstaffid(myCircle.getStaffId());
        myCircleDiscuss.setCreateTime(new Date().getTime() / 1000);
        myCircleDiscuss.setCreateUser(currentStaff.getId() + "");
        myCircleDiscuss.setStaffId(currentStaff.getId());
        myCircleDiscuss.setStaffName(currentStaff.getUserreal());
        myCircleDiscuss.setStaffLogo(currentStaff.getHeadimgurl());
        myCircleDiscuss.setRemark(currentStaff.getRemark());
        myCircleDiscuss.setIp(ToolsUtils.getIP());
        myCircleDiscuss = this.myCircleDiscussService.addEntity(myCircleDiscuss);
        if (!ObjectUtils.isEmpty(myCircleDiscuss)) {
            MyCircleDiscussDto result = new MyCircleDiscussDto();
            BeanUtils.copyProperties(myCircleDiscuss, result);
            return WxMiniResponse.ok(result);
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "评论失败！");
        }
    }

    /**
     * 点赞线圈
     *
     * @param queryParam 推荐信息【MyCircleQueryParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getCircleDiscuss")
    public WxMiniResponse getCircleDiscuss(@RequestBody MyCircleDiscussQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            //   return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam) || ObjectUtils.isEmpty(queryParam.getPid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }

        MyCircle myCircle = this.myCircleService.selectById(queryParam.getPid());
        if (ObjectUtils.isEmpty(myCircle)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }
        if (!ObjectUtils.isEmpty(currentStaff)) {
            if (currentStaff.getId().equals(myCircle.getStaffId())) {
                myCircleDiscussService.updateReaded(myCircle.getId(), currentStaff.getId(), null);
            }
        }
        queryParam.setPid(myCircle.getId());
        //这个是分页查询评论列表的代码
//        Page<MyCircleDiscuss> page = this.myCircleDiscussService.selectPageList(queryParam);
//        WxMiniPageDto<MyCircleDiscussDto> result = new WxMiniPageDto(page.getCurrent(), page.getSize());
//        BeanUtils.copyProperties(page, result);
//        List<MyCircleDiscussDto> convertList = page.getRecords().stream().map(po -> {
//            MyCircleDiscussDto myCircleDiscussDto = new MyCircleDiscussDto();
//            BeanUtils.copyProperties(po, myCircleDiscussDto);
//
//            MyCircleDiscussThumbupQueryParam myCircleThumbupQueryParam = new MyCircleDiscussThumbupQueryParam();
//            myCircleThumbupQueryParam.setPid(myCircle.getId());
//            myCircleThumbupQueryParam.setDid(po.getId());
//            // 点赞数
//            Long thumbups = this.myCircleDiscussThumbupService.selectCount(myCircleThumbupQueryParam);
//            myCircleDiscussDto.setThumbups(thumbups);
//            myCircleThumbupQueryParam.setStaffId(currentStaff.getId());
//            Long thumbup = this.myCircleDiscussThumbupService.selectCount(myCircleThumbupQueryParam);
//            if (ObjectUtils.isEmpty(thumbup) || thumbup == 0L) {
//                myCircleDiscussDto.setThumbup(1);
//            } else {
//                myCircleDiscussDto.setThumbup(0);
//            }
//        MyStaff userInfo = this.myStaffService.selectMyStaffById(po.getPid());
//        if (!ObjectUtils.isEmpty(userInfo)) {
//            myCircleDiscussDto.setFname(userInfo.getTitle());
//        }
//            return myCircleDiscussDto;
//        }).collect(Collectors.toList());
//        result.setData(convertList);

        // 查询所有的评论列表；
        List<MyCircleDiscuss> resultList = this.myCircleDiscussService.selectList(queryParam);
        List<MyCircleDiscussDto> convertList = resultList.stream().map(po -> {
            MyCircleDiscussDto myCircleDiscussDto = new MyCircleDiscussDto();
            BeanUtils.copyProperties(po, myCircleDiscussDto);

            MyCircleDiscussThumbupQueryParam myCircleThumbupQueryParam = new MyCircleDiscussThumbupQueryParam();
            myCircleThumbupQueryParam.setPid(myCircle.getId());
            myCircleThumbupQueryParam.setDid(po.getId());
            // 点赞数
            Long thumbups = this.myCircleDiscussThumbupService.selectCount(myCircleThumbupQueryParam);
            myCircleDiscussDto.setThumbups(thumbups);
            myCircleThumbupQueryParam.setStaffId(currentStaff.getId());
            Long thumbup = this.myCircleDiscussThumbupService.selectCount(myCircleThumbupQueryParam);
            if (ObjectUtils.isEmpty(thumbup) || thumbup == 0L) {
                myCircleDiscussDto.setThumbup(1);
            } else {
                myCircleDiscussDto.setThumbup(0);
            }
            if (!ObjectUtils.isEmpty(po.getFid()) && po.getFid() > 0) {
                MyStaff userInfo = this.myStaffService.selectMyStaffById(po.getFid());
                myCircleDiscussDto.setFname(userInfo.getTitle());
            }
            if (!ObjectUtils.isEmpty(po.getStaffId())) {
                MyStaff userInfo = this.myStaffService.selectMyStaffById(po.getStaffId());
                if (!ObjectUtils.isEmpty(userInfo)) {
                    //                myCircleDiscussDto.setFname(userInfo.getTitle());
                    myCircleDiscussDto.setStaffHeadimgurl(userInfo.getLogo());
                    //                myCircleDiscussDto.setStaffLogo(userInfo.getLogo());
                    myCircleDiscussDto.setStaffTitle(userInfo.getTitle());
                }
            }
            return myCircleDiscussDto;
        }).collect(Collectors.toList());
        return WxMiniResponse.ok(convertList);

    }

    @PostMapping("/getCircleDiscussList")
    public WxMiniResponse getCircleDiscussList(@RequestBody MyCircleDiscussQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        queryParam.setPstaffid(currentStaff.getId());
        queryParam.setParentid(0);
        queryParam.setOrderByFiled("id");
        queryParam.setOrderByType("desc");
        Page<MyCircleDiscuss> page = this.myCircleDiscussService.selectPageList(queryParam);
        WxMiniPageDto<MyCircleDiscussDto> result = new WxMiniPageDto(page.getCurrent(), page.getSize());
        BeanUtils.copyProperties(page, result);
        List<MyCircleDiscussDto> convertList = page.getRecords().stream().map(po -> {
            MyCircleDiscussDto myCircleDiscussDto = new MyCircleDiscussDto();
            BeanUtils.copyProperties(po, myCircleDiscussDto);
            if (!ObjectUtils.isEmpty(po.getStaffId())) {
                MyStaff userInfo = this.myStaffService.selectMyStaffById(po.getStaffId());
                if (!ObjectUtils.isEmpty(userInfo)) {
                    myCircleDiscussDto.setStaffHeadimgurl(userInfo.getLogo());
                    myCircleDiscussDto.setStaffTitle(userInfo.getTitle());
                }
            }
            return myCircleDiscussDto;
        }).collect(Collectors.toList());
        result.setData(convertList);
        myCircleDiscussService.updateReaded(null, currentStaff.getId(), currentStaff.getId());
        return WxMiniResponse.ok(result);
    }

    @PostMapping("/delCircleDiscuss")
    public WxMiniResponse delCircleDiscuss(@RequestBody MyCircleDiscussQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam) || ObjectUtils.isEmpty(queryParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }
        MyCircleDiscuss myCircleDiscuss = this.myCircleDiscussService.selectById(queryParam.getId());
        if (!ObjectUtils.isEmpty(myCircleDiscuss)) {
            MyCircle myCircle = this.myCircleService.selectById(myCircleDiscuss.getPid());
            if (ObjectUtils.isEmpty(myCircle)) {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "推荐（广告）信息不存在,或该条推荐（广告）信息已被删除！");
            }
            Boolean result = false;
            if (myCircle.getStaffId().equals(currentStaff.getId()) || myCircleDiscuss.getStaffId().equals(currentStaff.getId())) {
                result = this.myCircleDiscussService.deletetByIdParam(myCircleDiscuss.getId(), null);
            } else {
//                result = this.myCircleDiscussService.deletetByIdParam(myCircleDiscuss.getId(), currentStaff.getId());
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "删除失败，不能删除别人的评论或回复");
            }
            if (result) {
                return WxMiniResponse.ok(result);
            } else {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "删除失败，数据不存在或参数错误！");
            }
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "不存在该数据或已被删除！");
        }
    }

    /**
     * 推荐信息评论点赞
     *
     * @param queryParam 推荐信息评论点赞【MyCircleDiscussThumbupQueryParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setCircleDiscussThumbup")
    public WxMiniResponse setCircleDiscussThumbup(@RequestBody MyCircleDiscussThumbupQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam) || ObjectUtils.isEmpty(queryParam.getDid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条评论已被删除！");
        }
        MyCircleDiscuss myCircleDiscuss = this.myCircleDiscussService.selectById(queryParam.getDid());
        if (ObjectUtils.isEmpty(myCircleDiscuss)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条评论已被删除！");
        }
        queryParam.setPid(myCircleDiscuss.getPid());
        queryParam.setDid(myCircleDiscuss.getId());
        queryParam.setStaffId(currentStaff.getId());
        Long thumbup = this.myCircleDiscussThumbupService.selectCount(queryParam);
        if (!ObjectUtils.isEmpty(thumbup) && thumbup > 0L) {
            Boolean result = this.myCircleDiscussThumbupService.deleteByPidDidAndStaffId(myCircleDiscuss.getPid(), myCircleDiscuss.getId(), currentStaff.getId());
            if (result) {
                return WxMiniResponse.ok();
            }
        } else {
            MyCircleDiscussThumbup myCircleDiscussThumbup = new MyCircleDiscussThumbup();
            myCircleDiscussThumbup.setPid(myCircleDiscuss.getPid());
            myCircleDiscussThumbup.setDid(myCircleDiscuss.getId());
            myCircleDiscussThumbup.setStaffId(currentStaff.getId());
            myCircleDiscussThumbup.setStaffName(currentStaff.getUserreal());
            myCircleDiscussThumbup.setCreateTime(new Date().getTime() / 1000);
            myCircleDiscussThumbup.setCreateUser(currentStaff.getId() + "");
            myCircleDiscussThumbup = this.myCircleDiscussThumbupService.addEntity(myCircleDiscussThumbup);
            if (!ObjectUtils.isEmpty(myCircleDiscussThumbup) && !ObjectUtils.isEmpty(myCircleDiscussThumbup.getId()) && myCircleDiscussThumbup.getId() > 0) {
                return WxMiniResponse.ok(myCircleDiscussThumbup);
            }
        }
        return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "点赞失败！或id不正确");
    }

    /**
     * 收藏推荐信息
     *
     * @param queryParam 推荐信息【MyCircleQueryParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/setCircleCollection")
    public WxMiniResponse setCircleCollection(@RequestBody MyCircleCollectionQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam) || ObjectUtils.isEmpty(queryParam.getPid())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }

        MyCircle myCircle = this.myCircleService.selectById(queryParam.getPid());
        if (ObjectUtils.isEmpty(myCircle)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }

        MyCircleCollectionQueryParam myCircleCollectionQueryParam = new MyCircleCollectionQueryParam();
        myCircleCollectionQueryParam.setStaffId(currentStaff.getId());
        myCircleCollectionQueryParam.setPid(myCircle.getId());
        Long count = this.myCircleCollectionService.selectCount(myCircleCollectionQueryParam);
        if (!ObjectUtils.isEmpty(count) && count > 0L) {
            Boolean deleteResult = this.myCircleCollectionService.deleteByPidAndStaffId(myCircle.getId(), currentStaff.getId());
            if (deleteResult) {
                return WxMiniResponse.ok();
            } else {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败！");
            }
        } else {
            MyCircleCollection myCircleCollection = new MyCircleCollection();

            myCircleCollection.setPid(myCircle.getId());
            myCircleCollection.setStaffId(currentStaff.getId());
            myCircleCollection.setCreateTime(new Date().getTime() / 1000);
            myCircleCollection.setCreateUser(currentStaff.getId() + "");
            myCircleCollection.setCreateTime(new Date().getTime() / 1000);
            myCircleCollection.setStaffName(currentStaff.getUserreal());
            myCircleCollection.setStaffLogo(currentStaff.getHeadimgurl());
            myCircleCollection.setFid(myCircle.getStaffId());
            myCircleCollection.setRemark(currentStaff.getRemark());
            myCircleCollection = this.myCircleCollectionService.addEntity(myCircleCollection);
            if (!ObjectUtils.isEmpty(myCircleCollection)) {
                return WxMiniResponse.ok(myCircleCollection);
            }
        }
        return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败");
    }

    /**
     * 获取推荐信息收藏列表
     *
     * @param queryParam 推荐信息【MyCircleCollectionQueryParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getCircleCollectionList")
    public WxMiniResponse getCircleCollectionList(@RequestBody MyCircleCollectionQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        queryParam.setStaffId(currentStaff.getId());
        WxMiniPageDto<MyCircleDto> resultList = myCircleCollectionService.selectPageList(queryParam, currentStaff);
        return WxMiniResponse.ok(resultList);
    }

    /**
     * getCircleFavList_关注-获取我关注的用户发补的推荐信息；
     *
     * @param queryParam 关注信息【MyFactoryFavQueryParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getCircleFavList")
    public WxMiniResponse getCircleFavList(@RequestBody MyFactoryFavQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        queryParam.setStaffId(currentStaff.getId());
        WxMiniPageDto<MyCircleDto> resultList = myFactoryFavService.selectCirclePageList(queryParam, currentStaff);
        return WxMiniResponse.ok(resultList);
    }

    /**
     * updateShare_分享-记录分享数；
     *
     * @param queryParam 推荐信息【StaticParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/updateShare")
    public WxMiniResponse updateShare(@RequestBody StaticParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }
        myCircleService.addShareCount(queryParam.getId());
        return WxMiniResponse.ok();
    }

    /**
     * deleteCircleCollection_收藏-删除收藏
     *
     * @param queryParam 推荐信息【StaticParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/deleteCircleCollection")
    public WxMiniResponse deleteCircleCollection(@RequestBody StaticParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam) || ObjectUtils.isEmpty(queryParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }

        MyCircle myCircle = this.myCircleService.selectById(queryParam.getId());
        if (ObjectUtils.isEmpty(myCircle)) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "id不正确,或该条动态已被删除！");
        }

        MyCircleCollectionQueryParam myCircleCollectionQueryParam = new MyCircleCollectionQueryParam();
        myCircleCollectionQueryParam.setStaffId(currentStaff.getId());
        myCircleCollectionQueryParam.setPid(myCircle.getId());
        Long count = this.myCircleCollectionService.selectCount(myCircleCollectionQueryParam);
        if (!ObjectUtils.isEmpty(count) && count > 0L) {
            Boolean deleteResult = this.myCircleCollectionService.deleteByPidAndStaffId(myCircle.getId(), currentStaff.getId());
            if (deleteResult) {
                return WxMiniResponse.ok("已删除成功");
            } else {
                return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败！");
            }
        }
        return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "删除失败");
    }

    /**
     * getCircleList_推荐信息-获取首页推荐信息列表；
     *
     * @param queryParam 推荐信息【MyCircleSaveParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/getCircleList")
    public WxMiniResponse getCircleList(@RequestBody MyCircleQueryParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
//        System.out.println(queryParam);
        if (ObjectUtils.isEmpty(queryParam.getUtype()) || !queryParam.getUtype().equals(1)) {
            WxMiniPageDto<MyCircleDto> pageDto = myCircleService.selectStaffToCirclePageList(queryParam);
            List<MyCircleDto> convertList = pageDto.getData().stream().map(po -> {
                po.setIsfav(0);
                if (!ObjectUtils.isEmpty(currentStaff) && !ObjectUtils.isEmpty(currentStaff.getId())) {
                    // 自己是否已关注
                    MyFactoryFavQueryParam myFactoryFavQueryParam = new MyFactoryFavQueryParam();
                    myFactoryFavQueryParam.setFavStaffid(po.getStaffId());
                    myFactoryFavQueryParam.setStaffId(currentStaff.getId());
                    Long favCount = this.myFactoryFavService.selectCount(myFactoryFavQueryParam);
                    if (favCount > 0L) {
                        po.setIsfav(1);
                    }
                }
                po.setVideo(StringEscapeUtils.unescapeHtml4(po.getVideo()));
                po.setContent(StringEscapeUtils.unescapeHtml4(po.getContent()));
                po.setCompanyContent(StringEscapeUtils.unescapeHtml4(po.getCompanyContent()));
                return po;
            }).collect(Collectors.toList());
            pageDto.setData(convertList);
            return WxMiniResponse.ok(pageDto);
        } else {
            Page<MyCircle> page = myCircleService.selectPageList(queryParam);
            if(!ObjectUtils.isEmpty(queryParam.getShareVideoId())&&queryParam.getShareVideoId()>0){
                MyCircle myCircle = myCircleService.selectById(queryParam.getShareVideoId());
               if(queryParam.getPage()==1){
                   if(!ObjectUtils.isEmpty(myCircle)){
                       page.getRecords().set(0,myCircle);
                   }

               }
            }
            WxMiniPageDto<MyCircleDto> wxMiniPageDto = new WxMiniPageDto(page.getCurrent(), page.getSize());
            BeanUtils.copyProperties(page, wxMiniPageDto);
            List<MyCircleDto> convertList = page.getRecords().stream().map(po -> {
                MyCircleDto myCircleDto = new MyCircleDto();
                BeanUtils.copyProperties(po, myCircleDto);
                MyCircleDiscussQueryParam myCircleDiscussQueryParam = new MyCircleDiscussQueryParam();
                myCircleDiscussQueryParam.setPid(po.getId());
                myCircleDiscussQueryParam.setParentid(0);
                Long discussCount = this.myCircleDiscussService.selectCount(myCircleDiscussQueryParam);
                if (ObjectUtils.isEmpty(discussCount)) {
                    discussCount = 0L;
                }
                // 评论数
                myCircleDto.setDiscuss(discussCount);
                myCircleDto.setVideo(StringEscapeUtils.unescapeHtml4(myCircleDto.getVideo()));
                MyCircleThumbupQueryParam myCircleThumbupQueryParam = new MyCircleThumbupQueryParam();
                myCircleThumbupQueryParam.setPid(po.getId());
                // 点赞数
                Long thumbups = this.myCircleThumbupService.selectCount(myCircleThumbupQueryParam);
                myCircleDto.setThumbups(thumbups);
                myCircleDto.setThumbup(1);
                if (!ObjectUtils.isEmpty(currentStaff) && !ObjectUtils.isEmpty(currentStaff.getId())) {
                    myCircleThumbupQueryParam.setStaffId(currentStaff.getId());
                    Long thumbup = this.myCircleThumbupService.selectCount(myCircleThumbupQueryParam);
                    // 自己是否已点赞
                    if (thumbup > 0L) {
                        myCircleDto.setThumbup(0);
                    }
                }
                // 自己是否已收藏
                MyCircleCollectionQueryParam myCircleCollectionQueryParam = new MyCircleCollectionQueryParam();
                myCircleCollectionQueryParam.setPid(po.getId());
                Long collections = this.myCircleCollectionService.selectCount(myCircleCollectionQueryParam);
                myCircleDto.setCollections(collections);
                myCircleDto.setCollection(1);
                if (!ObjectUtils.isEmpty(currentStaff) && !ObjectUtils.isEmpty(currentStaff.getId())) {
                    myCircleCollectionQueryParam.setStaffId(currentStaff.getId());
                    Long collectionCount = this.myCircleCollectionService.selectCount(myCircleCollectionQueryParam);
                    if (collectionCount > 0L) {
                        myCircleDto.setCollection(0);
                    }
                }
                myCircleDto.setIsfav(0);
                if (!ObjectUtils.isEmpty(currentStaff) && !ObjectUtils.isEmpty(currentStaff.getId())) {
                    // 自己是否已关注
                    MyFactoryFavQueryParam myFactoryFavQueryParam = new MyFactoryFavQueryParam();
                    myFactoryFavQueryParam.setFavStaffid(po.getStaffId());
                    myFactoryFavQueryParam.setStaffId(currentStaff.getId());
                    Long favCount = this.myFactoryFavService.selectCount(myFactoryFavQueryParam);
                    if (favCount > 0L) {
                        myCircleDto.setIsfav(1);
                    }
                }
                myCircleDto.setVideo(StringEscapeUtils.unescapeHtml4(po.getVideo()));
                myCircleDto.setContent(StringEscapeUtils.unescapeHtml4(po.getContent()));
                myCircleDto.setCompanyContent(StringEscapeUtils.unescapeHtml4(po.getCompanyContent()));
                return myCircleDto;
            }).collect(Collectors.toList());
            wxMiniPageDto.setData(convertList);
            return WxMiniResponse.ok(wxMiniPageDto);
        }
    }

    /**
     * deleteCircle_推荐信息-删除推荐信息
     *
     * @param queryParam 推荐信息【StaticParam】标准查询参数类；
     * @return 标准响应体封装推荐信息返回数据
     * @Author chenk
     * @Version 1.0.1
     */
    @PostMapping("/deleteCircle")
    public WxMiniResponse deleteCircle(@RequestBody StaticParam queryParam) {
        if (!this.isCheckLogin(queryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (ObjectUtils.isEmpty(queryParam.getId())) {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "操作失败，参数推荐信息标识为空！");
        }
        Boolean result = this.myCircleService.deleteByIdAndSearch(queryParam.getId());
        if (result) {
            return WxMiniResponse.ok("已删除成功！");
        } else {
            return WxMiniResponse.error(ResultEnum.ERROR.getKey(), "删除失败");
        }
    }


    /**
     * @api {GET} /Circle/addCircleVideoPlayNumber 添加视频播放量
     * @apiParam {int} id 线缆圈id
     */
    @PostMapping("/addCircleVideoPlayNumber")
    public WxMiniResponse addCircleVideoPlayNumber(@RequestBody StaticParam staticParam) {
//        if (!this.isCheckLogin(staticParam.getGuid())) {
//            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
//            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
//        }
        if (staticParam.getId() > 0) {
            MyCircle circle = myCircleService.selectById(staticParam.getId());
            if (circle != null) {
                circle.setVideoPlay(circle.getVideoPlay() + 1);
                myCircleService.updateEntity(circle);
            }
        }
        return WxMiniResponse.ok();
    }


    /**
     * @api {GET} verifyCircle  验证线缆圈
     * @apiParam {int} id 线缆圈id
     */
    @PostMapping("/verifyCircle")
    public WxMiniResponse verifyCircle(@RequestBody StaticParam staticParam) {
        if (!this.isCheckLogin(staticParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
           // return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        if (!ObjectUtils.isEmpty(staticParam.getId())) {
            MyCircle circle = myCircleService.selectById(staticParam.getId());

            if (ObjectUtils.isEmpty(circle)) {
                return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "信息不存在或已被删除", "信息不存在或已被删除");
            }
            if (circle.getStatus().equals(0)) {
                return WxMiniResponse.error(ResultEnum.ERROR2012.getKey(), "信息不存在或已被删除", "信息不存在或已被删除");
            }

        } else if(!ObjectUtils.isEmpty(staticParam.getGuid())){
            MyCircleQueryParam queryParam = new MyCircleQueryParam();
            queryParam.setStaffId(currentStaff.getId());
            queryParam.setType(3);
            queryParam.setStatus(1);
            Page<MyCircle> page = this.myCircleService.selectPageList(queryParam);
            MyCircle myCircle = new MyCircle();
            if (!ObjectUtils.isEmpty(page)) {
                if (page.getTotal() > 0) {
                    myCircle = page.getRecords().get(0);
                    myCircle.setVideo(StringEscapeUtils.unescapeHtml4(myCircle.getVideo()));
                    myCircle.setContent(StringEscapeUtils.unescapeHtml4(myCircle.getContent()));
                    myCircle.setCompanyContent(StringEscapeUtils.unescapeHtml4(myCircle.getCompanyContent()));
                    MyCircleDto myCircleDto = new MyCircleDto();
                    BeanUtils.copyProperties(myCircle, myCircleDto);
                    return WxMiniResponse.ok(myCircleDto);
                }
            }
        }
        return WxMiniResponse.ok(null);
    }

}
